"""
Global setting of the trading platform.
"""

from logging import CRITICAL
from typing import Dict, Any
from tzlocal import get_localzone_name

from .utility import load_json


SETTINGS: Dict[str, Any] = {
    "font.family": "微软雅黑",
    "font.size": 12,

    "log.active": True,
    "log.level": CRITICAL,
    "log.console": True,
    "log.file": True,

    "email.server": "smtp.163.com",
    "email.port": 587,
    "email.username": "cjiewong@163.com",
    "email.password": "MXRPNEGLGSBNWXMT",
    "email.sender": "cjiewong@163.com",
    "email.receiver": "chaojie.huang@91chengguo.com",

    "push.active": True,
    "serverchan.key": "SCT172013TgrbSxiCxdlXRMVgABHY6OPWD",

    "datafeed.name": "udata",
    "datafeed.username": "token",
    "datafeed.password": "bDHXJB7YDYZ1ZLuRdOg_ASECFVp-EBrOVIoqhIn_ENl2Owpq0vK-752a4qujAuPc",

    "database.timezone": get_localzone_name(),
    "database.name": "mysql",
    "database.database": "vnpy",
    "database.host": "localhost",
    "database.port": 3306,
    "database.user": "root",
    "database.password": "root"
}


# Load global setting from json file.
SETTING_FILENAME: str = "vt_setting.json"
SETTINGS.update(load_json(SETTING_FILENAME))


def get_settings(prefix: str = "") -> Dict[str, Any]:
    prefix_length: int = len(prefix)
    return {k[prefix_length:]: v for k, v in SETTINGS.items() if k.startswith(prefix)}
